﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link href="CSS/StyleSheet.css" rel="stylesheet" type="text/css" />
    <title></title>
  <script src="jquery-1.4.2.min.js" type="text/javascript"></script>

    <script src="json2.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
<!--

        var NumOfQuaRow = 0;
        var NumOfCertRow = 0;


        function replaceToUpper(key, value) {
            return value.toString().toUpperCase();
        }

        function AddQualifications_onclick() {
            NumOfQuaRow++;

            // get the refference of the main Div
            var mainDiv = document.getElementById('QuaDiv');

            // create new div that will work as a container
            var newDiv = document.createElement('div');
            newDiv.setAttribute('id', 'innerDiv' + NumOfQuaRow);

            // create new textbox for email entry
            var newTextBox = document.createElement('input');
            newTextBox.type = 'text';
            newTextBox.setAttribute('id', 'txtQua' + NumOfQuaRow);

            // create remove button for each email adress

//            var newButton = document.createElement('input');
//            newButton.type = 'button';
//            newButton.value = 'Remove';
//            newButton.id = 'btn' + NumOfQuaRow;

//            // atach event for remove button click
//            newButton.onclick = function RemoveEntry() {
//                var mainDiv = document.getElementById('QuaDiv');
//                mainDiv.removeChild(this.parentNode);
//            }

            // append the span, textbox and the button
            newDiv.appendChild(newTextBox);
//            newDiv.appendChild(newButton);

            // finally append the new div to the main div
            mainDiv.appendChild(newDiv);

        }

        function AddCertifications_onclick() {
            NumOfCertRow++;

            // get the refference of the main Div
            var mainDiv = document.getElementById('CertDiv');

            // create new div that will work as a container
            var newDiv = document.createElement('div');
            newDiv.setAttribute('id', 'innerDiv' + NumOfCertRow);

            // create new textbox for email entry
            var newTextBox = document.createElement('input');
            newTextBox.type = 'text';
            newTextBox.setAttribute('id', 'txtCert' + NumOfCertRow);

            // create remove button for each email adress

//            var newButton = document.createElement('input');
//            newButton.type = 'button';
//            newButton.value = 'Remove';
//            newButton.id = 'btn' + NumOfCertRow;

//            // atach event for remove button click
//            newButton.onclick = function RemoveEntry() {
//                var mainDiv = document.getElementById('CertDiv');
//                mainDiv.removeChild(this.parentNode);
//                mainDiv.
//            }

            // append the span, textbox and the button
            newDiv.appendChild(newTextBox);
           // newDiv.appendChild(newButton);

            // finally append the new div to the main div
            mainDiv.appendChild(newDiv);

        }

//        function getCheckedRadio() {
//            var radioButtons = document.getElementsByName("rbdGender");
//            for (var x = 0; x < radioButtons.length; x++) {
//                if (radioButtons[x].checked) {
//                    alert("You checked " + radioButtons[x].id + " which has the value " + radioButtons[x].value);
//                    return radioButtons[x].value;
//                }
//            }
//        }

        function getCheckedRadio() {
            var radioButtons = document.getElementsByName("rbdGender");
            for (var x = 0; x < radioButtons.length; x++) {
                if (radioButtons[x].checked) {
                   return radioButtons[x].value;
                }
            }
        }
        function btnSave_onclick() {

            
            //            var objEmployees = new Array();
            //            var objEmployee = {};
            //            objEmployee.Name = "John";
            //            objEmployee.Age = "20";
            //            objEmployee.Address = "Address of John";
            //            objEmployees[0] = objEmployee;

            var objRS = {};
            objRS.FirstName = document.getElementById("<%=txtFN.ClientID%>").value;
            objRS.LastName = document.getElementById("<%=txtLN.ClientID%>").value;
            objRS.Gender = getCheckedRadio();
            var e = document.getElementById("cmbNationality");
            objRS.Nationality = e.options[e.selectedIndex].value;
            objRS.ContactNumber = document.getElementById("<%=txtContactNumber.ClientID%>").value;
            objRS.Email = document.getElementById("<%=txtEmail.ClientID%>").value;
            var e1 = document.getElementById("cmbVisaStatus");
            objRS.VisaStatus = e1.options[e1.selectedIndex].value;
            objRS.Address = document.getElementById("<%=txtAddress.ClientID%>").value;
            objRS.TotExp = document.getElementById("<%=txtExperience.ClientID%>").value;
            objRS.RelExp = document.getElementById("<%=txtRelavantExp.ClientID%>").value;
            objRS.NoticePeriod = document.getElementById("<%=txtNoticePeriod.ClientID%>").value;
            objRS.CurrentSalary = document.getElementById("<%=txtCurrentSalary.ClientID%>").value;
            objRS.ExpectedSalaryFrom = document.getElementById("<%=txtExpSalFrom.ClientID%>").value;
            objRS.ExpectedSalaryTo = document.getElementById("<%=txtExpSalTo.ClientID%>").value;
            objRS.ResumeTitle = document.getElementById("<%=txtResTitle.ClientID%>").value;
            objRS.ResumeText = document.getElementById("<%=txtResumeText.ClientID%>").value;

            objRS.Qualifications = new Array();
            for (var x = 0; x <= NumOfQuaRow; x++) {
                var fieldID = 'txtQua' + x;
                var qua = document.getElementById(fieldID).value;
                if (qua != null) {
                    var objQua = {};
                    objQua.ID = x;
                    objQua.Name = qua;
                    objRS.Qualifications[x] = objQua;
                }

            }

            objRS.ProfCertifications = new Array();
            for (var x = 0; x <= NumOfCertRow; x++) {
                var fieldID = 'txtCert' + x;
                var qua = document.getElementById(fieldID).value;
                if (qua != null) {
                    var objCert = {};
                    objCert.ID = x;
                    objCert.Name = qua;
                    objRS.ProfCertifications[x] = objCert;
                }

            } 

            var json = JSON.stringify({ "objResumeSubmit": objRS, "name": "Vijay" });
            alert(json);

            $.ajax({
                type: "POST",
                url: "Default.aspx/AddResume",
                data: json,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(data) {
                    alert(data.d);
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    //handling the error message thrown by c# code
                    var jsonValue = (new Function("return( " + xhr.responseText + " );"))();
                    alert(jsonValue.Message);
                    alert(xhr.status);
                    alert(thrownError);
                }
            });
        }

        function getCheckedValue(radioObj) {
            if (!radioObj)
                return "";
            var radioLength = radioObj.length;
            if (radioLength == undefined)
                if (radioObj.checked)
                return radioObj.value;
            else
                return "";
            for (var i = 0; i < radioLength; i++) {
                if (radioObj[i].checked) {
                    return radioObj[i].value;
                }
            }
            return "";
        }
// -->
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="HeadDiv" runat="server">
        <table>
            <tr>
                <td class="tblColumnHeader" colspan="2">
                    Personal Details
                </td>
                <td class="tblColumnHeader">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    First name :
                </td>
                <td>
                    <asp:TextBox ID="txtFN" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Last Name :
                </td>
                <td>
                    <asp:TextBox ID="txtLN" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Gender
                </td>
                <td>
                    <asp:RadioButtonList ID="rbdGender" runat="server">
                        <asp:ListItem Value="M">Male</asp:ListItem>
                        <asp:ListItem Value="F">Female</asp:ListItem>
                    </asp:RadioButtonList>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Nationality
                </td>
                <td>
                    <asp:DropDownList ID="cmbNationality" runat="server">
                    </asp:DropDownList>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Contact number
                </td>
                <td>
                    <asp:TextBox ID="txtContactNumber" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Email
                </td>
                <td>
                    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Visa Status
                </td>
                <td>
                    <asp:DropDownList ID="cmbVisaStatus" runat="server">
                    </asp:DropDownList>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Current Address
                </td>
                <td>
                    <asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader" colspan="2">
                    Education
                </td>
                <td class="tblColumnHeader">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Qualifications
                </td>
                <td>
                    <div id="QuaDiv" runat="server">
                        <asp:TextBox ID="txtQua0" runat="server"></asp:TextBox>
                    </div>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader" colspan="1">
                    &nbsp;
                </td>
                <td class="tblColumnHeader">
                    <input id="btnQuaAddmore" type="button" value="Add More" onclick="AddQualifications_onclick()" />
                </td>
                <td class="tblColumnHeader">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader" colspan="2">
                    Work Experience
                </td>
                <td class="tblColumnHeader">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Professional Certifications
                </td>
                <td>
                    <div id="CertDiv" runat="server">
                        <asp:TextBox ID="txtCert0" runat="server"></asp:TextBox>
                    </div>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader" colspan="1">
                    &nbsp;
                </td>
                <td class="tblColumnHeader">
                    <input id="btnCertAddmore" type="button" value="Add More" onclick="AddCertifications_onclick()" />
                </td>
                <td class="tblColumnHeader">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Total Experience (years)
                </td>
                <td>
                    <asp:TextBox ID="txtExperience" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Relevant Experience (years)
                </td>
                <td>
                    <asp:TextBox ID="txtRelavantExp" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Notice period (months)
                </td>
                <td>
                    <asp:TextBox ID="txtNoticePeriod" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Current Salary
                </td>
                <td>
                    <asp:TextBox ID="txtCurrentSalary" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Expected Salary
                </td>
                <td>
                    <asp:TextBox ID="txtExpSalFrom" runat="server"></asp:TextBox>
                </td>
                <td>
                    <asp:TextBox ID="txtExpSalTo" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader" colspan="2">
                    Resume
                </td>
                <td class="tblColumnHeader">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Resume Title
                </td>
                <td>
                    <asp:TextBox ID="txtResTitle" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Resume In text format
                </td>
                <td>
                    <asp:TextBox ID="txtResumeText" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td class="tblColumnHeader">
                    Resume in Word
                </td>
                <td>
                    <asp:FileUpload ID="futool" runat="server" />
                </td>
                <td>
                    &nbsp;
                </td>
            </tr>
        </table>
    </div>
    <input id="btnSave" type="button" value="Save" onclick="btnSave_onclick()" />
    </form>
</body>
</html>
